﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using IntelligentFiles.HcForm;
using Common;

namespace IntelligentFiles.HcControl
{
    public partial class box : UserControl
    {
        public box()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 物品数量
        /// </summary>
        int Num = 0;
        /// <summary>
        /// 格子ID
        /// </summary>
        string boxId = "";

        /// <summary>
        /// 是否可操作性
        /// 管理员登陆全部可操作性
        /// 用户登录只操作自己拥有的
        /// </summary>
        bool flag = true;
        /// <summary>
        /// 格子赋值
        /// </summary>
        /// <param name="No"></param>
        /// <param name="num"></param>
        /// <param name="ID"></param>
        /// <param name="type">0 管理员登陆 全部显示 1用户登录 只显示自己可用</param>
        public void setBox(string No, int num, string ID,int type,bool _flag)
        {
            try
            {
                flag = _flag;
                //位置计算
                lab_No.Text = No;

                int No_x = (this.Width - lab_No.Width) / 2;
                int No_y = this.Height / 3;
                lab_No.Location = new Point(No_x, No_y);

                if (flag)
                {
                    
                    
                  
                    if (num == 3)
                    {
                        Num = num;
                        lab_num.Text = num + " / 本";
                        //占用
                        this.BackColor = Color.FromArgb(2, 215, 233);
                        int num_x = (this.Width - lab_num.Width) / 2;
                        int num_y = (this.Height / 3) * 2;
                        lab_num.Location = new Point(num_x, num_y);
                    }
                    else
                    {
                         if (type == 1)
                        {
                            this.BackColor =  Color.FromArgb(2, 215, 233);
                        }
                        lab_num.Text = "";
                    }
                }
                else
                {
                    lab_num.Text = "";
                }

                

            }
            catch(Exception ex)
            {
                CommonApi.writeLog("格子赋值异常,"+ex.ToString());
            }

     
        }


        private void panel_back_Click(object sender, EventArgs e)
        {
            if (flag)
            {
                Opearttion_box op = new Opearttion_box();
                op.setBoxNaame(lab_No.Text, Num);
                op.Show();
            }
        }

        private void panel_back_Paint(object sender, PaintEventArgs e)
        {

        }
    }
}
